/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.mallsite.modules.shop.entity;

import javax.validation.Valid;

import com.jeesite.common.mybatis.annotation.Column;
import com.jeesite.common.mybatis.annotation.JoinTable;
import com.jeesite.common.mybatis.annotation.JoinTable.Type;
import com.jeesite.common.mybatis.annotation.Table;
import com.jeesite.modules.sys.entity.User;

/**
 * 店铺Entity
 * @author ruyang
 * @version 2020-12-08
 */
@Table(name="${_prefix}sys_user", alias="a", columns={
		@Column(includeEntity=User.class),
	}, joinTable={
		@JoinTable(type=Type.JOIN, entity=Shop.class, alias="e",
			on="e.shop_id=a.ref_code AND a.user_type=#{USER_TYPE_SHOP}"),
	},
	orderBy="a.user_weight DESC, a.update_date DESC"
)
public class ShopUser extends User {
	
	private static final long serialVersionUID = 1L;
	
	public static final String USER_TYPE_SHOP = "shop";
	
	public ShopUser() {
		this(null);
	}

	public ShopUser(String id){
		super(id);
	}
	
	@Valid
	public Shop getShop(){
		Shop shop = (Shop)super.getRefObj();
		if (shop == null){
			shop = new Shop(getRefCode());
			super.setRefObj(shop);
		}
		return shop;
	}
	
	public void setShop(Shop shop){
		super.setRefObj(shop);
	}
}